// 页面加载完成后执行
window.addEventListener('load', function() {
    // 隐藏加载动画
    const loader = document.querySelector('.loader');
    if (loader) {
        loader.classList.add('hidden');
    }

    // 侧边栏切换
    const sidebarToggle = document.getElementById('sidebarToggle');
    const sidebar = document.getElementById('sidebar');
    const mainContent = document.getElementById('mainContent');
    const mobileSidebarToggle = document.getElementById('mobileSidebarToggle');

    if (sidebarToggle && sidebar && mainContent) {
        sidebarToggle.addEventListener('click', () => {
            // 切换侧边栏状态
            sidebar.classList.toggle('collapsed');
            // 切换主内容区域状态
            mainContent.classList.toggle('expanded');
            // 切换按钮图标
            const toggleIcon = sidebarToggle.querySelector('.toggle-icon');
            if (sidebar.classList.contains('collapsed')) {
                toggleIcon.classList.remove('fa-angle-left');
                toggleIcon.classList.add('fa-angle-right');
            } else {
                toggleIcon.classList.remove('fa-angle-right');
                toggleIcon.classList.add('fa-angle-left');
            }
        });
    }

    if (mobileSidebarToggle && sidebar) {
        mobileSidebarToggle.addEventListener('click', () => {
            sidebar.classList.toggle('open');
        });
    }

    // 点击主内容区域关闭侧边栏（移动端）
    if (mainContent && sidebar) {
        mainContent.addEventListener('click', () => {
            if (sidebar.classList.contains('open')) {
                sidebar.classList.remove('open');
            }
        });
    }
});